package edu.zut.main.thread;

public class ThreadDemo2 {
    public static void main(String[] args) {
        System.out.println("主线程开始");
        //利用接口形式创建子线程
        Thread thread = new Thread(new ThreadB(), "thread-B");
        //让当前子线程处于就绪
        thread.start();

        System.out.println("主线程结束");
    }

}

//线程创建的第二种方式   实现Runnable接口
class ThreadB implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"执行");
            try {
                //让当前线程休眠3s
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
